$(window).load(function() { 
	$('body').fadeOut(10, function() { $(this).show(); }); 
});

$(document).ready(function() {
	$(document).height = '250px';
	
	tooltip();
	
	$('#radio_filter').buttonset();
	
	$('#time_range_type').change(function() {
		var trv = $('#time_range_value')
		if (this.value == 'min') {
			trv.spinner({ max: 59, min: 1 });
			trv.val(60);
		} else if (this.value == 'hours') {
			trv.spinner({ max: 24, min: 1 });
			trv.val(24);
		} else if (this.value == 'days') {
			trv.spinner({ max: 31, min: 1 });
			trv.val(31);
		} else if (this.value == 'wks') {
			trv.spinner({ max: 52, min: 1 });
			trv.val(52);
		}
	});
	
	$("radio_filter").click(function(event) {
		console.log($("radio_filter:checked")[0]);
	});
	
	$("#time_range_type option:eq('min')").prop("selected", true);
	$("#time_range_type").trigger("change");
	
	for (var x in itemType) { 
		var val = (new String(x)).capitalize();
		$("#type_range").append($('<option>', { value: val, text: val }));
	}
});

this.tooltip = function(){	
	xOffset = 10;
	yOffset = 20;
	tWidth = 300;
	$("div.icon.help.tooltip-left").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<p class='eom' id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("width", tWidth + "px")
			.css("position", "absolute")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });
	$("div.icon.help.tooltip-left").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
	
	$("div.icon.help.tooltip-right").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<p class='eom' id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("width", tWidth + "px")
			.css("position", "absolute")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX - (tWidth + (yOffset *2))) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });
	$("div.icon.help.tooltip-right").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX - (tWidth + (yOffset *2))) + "px");
	});
};

/*
CODE: gets the name and time that an allie last sent you a gift/request
var nm = [];
 $.indexedDB(DB_NAME).objectStore("History").each(function(v) { 
	nm.push({id: v.value.uname, ts: v.value.timestamp});
}).done(function() { 
	var dt = []; 
	var names = _.groupBy(nm, 'id');
	for (var z in names) { 
		names[z].sort(function(a, b) { 
			return a.ts - b.ts ;
		});
		dt.push({name:z, ts:names[z][names[z].length - 1].ts})
	}  
	dt.sort(function(a,b) { 
		return a.ts - b.ts; 
	}); 
	for (var z in dt) { 
		console.log((new Date(dt[z].ts * 1000)) + ' ' + dt[z].name) 
	} 
});
*/






